using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ChuanPlus.DAO;
using ChuanPlus.Utils;
namespace ChuanPlus.FormControl
{
    public partial class ControlSalesReport : DevExpress.XtraEditors.XtraUserControl
    {
        public ControlSalesReport()
        {
            InitializeComponent();
        }

        private void buttonLoad_Click(object sender, EventArgs e)
        {
            try
            {
                if (validateDate())
                {
                    if (comboBoDistributor.Text == "")  // if user not select distributor, return
                    {
                        MessageBox.Show("Please select Distributor", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    clsReport report = new clsReport();
                    report.ExportSaleReportToExcel("Sale Report", OrderDAO.GetSaleReport(dateFrom.DateTime, dateTo.DateTime, comboBoDistributor.SelectedIndex + 1), 13);
                }                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void buttonCollectionRpt_Click(object sender, EventArgs e)
        {
            try
            {
                if (validateDate())
                {
                    clsReport report = new clsReport();             
                    report.ExportCollectionReport(ReceiptVoucherDAO.GetCollectionReport(dateFrom.DateTime, dateTo.DateTime), dateFrom.DateTime, dateTo.DateTime);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }         
        }
        private bool validateDate()
        {
            if (dateFrom.Text == "")
            { 
                MessageBox.Show("Please select from date","Message", MessageBoxButtons.OK,MessageBoxIcon.Information);
                dateFrom.Focus();
                return false;
            }
            if(dateTo.Text == "")
            {
                MessageBox.Show("Please select to date","Message", MessageBoxButtons.OK,MessageBoxIcon.Information);
                dateTo.Focus();
                return false;
            }
            return true;
        }      
    }
}
